//package com.poly.common.core.security.advice;
//
//import com.poly.common.core.security.annotation.RequestDecrypt;
//import com.poly.common.core.security.config.SecretKeyConfig;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.MethodParameter;
//import org.springframework.http.HttpInputMessage;
//import org.springframework.http.converter.HttpMessageConverter;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice;
//
//import java.lang.reflect.Type;
//
//@Slf4j
//@ControllerAdvice
//public class EncryptRequestBodyAdvice  implements RequestBodyAdvice {
//
//    private boolean encrypt;
//
//    @Autowired
//    private SecretKeyConfig secretKeyConfig;
//
//    @Override
//    public boolean supports(MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
//        if (methodParameter.getMethod().isAnnotationPresent(RequestDecrypt.class) && !secretKeyConfig.isDebug()) {
//            encrypt = true;
//        }
//        return encrypt;
//    }
//
//    @Override
//    public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
//        return body;
//    }
//
//    @Override
//    public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
//                                           Class<? extends HttpMessageConverter<?>> converterType){
//        if (encrypt&&parameter.getMethod().isAnnotationPresent(RequestDecrypt.class)) {
//            try {
//                return new DecryptHttpInputMessage(inputMessage, secretKeyConfig.getPrivateKey(), secretKeyConfig.getCharset());
//            } catch (Exception e) {
//                throw new IllegalArgumentException("解密失败！");
//            }
//        }
//        return inputMessage;
//    }
//
//    @Override
//    public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
//                                Class<? extends HttpMessageConverter<?>> converterType) {
//        return body;
//    }
//}
